﻿using MediatR;
using PersonnelManagement.Application.Command.ManpowerCommand;
using PersonnelManagement.Infrstructre.Interface;
using SqlSugar;

namespace PersonnelManagement.Application.CommandHandler.ManpowerCommandHandler
{
    /// <summary>
    /// 删除人员档案
    /// </summary>
    public class DelManpowerCommandHandler : IRequestHandler<DelManpowerCommand, int>
    {
        IManpowerRepostiory mRep;

        public DelManpowerCommandHandler(IManpowerRepostiory mRep)
        {
            this.mRep = mRep;
        }

        public async Task<int> Handle(DelManpowerCommand request, CancellationToken cancellationToken)
        {
            var list = (await mRep.Getall()).Where(c=> request.ManpowerId.Contains(c.ManpowerId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelTime = DateTime.Now;
                await mRep.UpdateAsymc(item);
            }
            return 1;
        }
    }
}
